package chapter06

object Test06_ConstructorParams {
  def main(args: Array[String]): Unit = {
    val teacher1 = new Teacher1
    println(s"teacher1: name = ${teacher1.name}, age = ${teacher1.age}")
    val teacher2 = new Teacher2("bob", 26)
    println(s"teacher2: name = ${teacher2.name}, age = ${teacher2.age}")
    teacher2.age = 29
    val teacher3 = new Teacher3("alice", 25)
    //不能修改属性值
    // teacher3.age = 27
    println(s"teacher3: name = ${teacher3.name}, age = ${teacher3.age}")
  }
}

class Teacher1 {
  //定义属性
  var name: String = _
  var age: Int = _
}

//上面定义等价于如下，这是全局变量
class Teacher2(var name: String, var age: Int)

class Teacher3(val name: String, val age: Int)